#!/bin/sh
# *************************************************************************
# This script can be used to start the WebLogic NodeManager
#
# To start the NodeManager on <host> and <port>, set the LISTEN_ADDRESS 
# variable to <host> and LISTEN_PORT variable to <port> before calling this 
# script.
#
# This script sets the following variables before starting the NodeManager:
# 
# BEA_HOME       - The BEA root installation directory.
# WL_HOME        - The root directory of your WebLogic installation.
# NODEMGR_HOME   - The root directory for this NodeManagerInstance.
# JAVA_HOME      - Location of the version of Java used to start WebLogic 
#                  Server. This variable must point to the root directory of a 
#                  JDK installation and will be set for you by the installer. 
#                  See the WebLogic platform support page 
#                  (@DOCSHOST/platforms/index.html) for an up-to-date list of 
#                  supported JVMs on Windows NT.
# PATH           - Adds the JDK and WebLogic directories to the system path.  
# CLASSPATH      - Adds the JDK and WebLogic jars to the classpath.  
# JAVA_OPTIONS   - Java command-line options for running the server. (These
#                  will be tagged on to the end of the JAVA_VM and MEM_ARGS)
# JAVA_VM        - The java arg specifying the VM to run.  (i.e. -server, 
#                  -hotspot, etc.)
# MEM_ARGS       - The variable to override the standard memory arguments
#                  passed to java
#
# Alternately, this script will take the first two positional parameters and 
# set them to LISTEN_ADDRESS and LISTEN_PORT. For instance, you could call this
# script: "sh startNodeManager.sh holly 7777" to start the NodeManager
# on host holly and port 7777, or just "sh startNodeManager.sh holly" 
# to start the node manager on host holly.
# *************************************************************************
# SMF Macros
.. /lib/svc/share/smf_include.sh

#########################################################
#                                                       #
#    res_apps1 server related varible declaration       #  
#                                                       #
#########################################################
cargores_site_dir=/afls_res/booking/managed/cargores/site
export cargores_site_dir
cargores_install_name=aa
export cargores_install_name
cargores_env_name=default
export cargores_env_name
cargores_server_mode=container
export cargores_server_mode
cargores_server_type=apps
export cargores_server_type
ASPECT_VIEWER=-javaagent:/afls_res/booking/managed/cargores/latest/lib/WEB-INF/lib/aspectjweaver-1.6.8.jar
export ASPECT_VIEWER
JASPER_OPTIONS="-Djasper.reports.compile.class.path=/afls_res/booking/managed/cargores/latest/lib/WEB-INF/lib/jasperreports-2.0.4.jar:/afls_res/booking/managed/cargores/latest/lib/itext-2.1.5.jar -Djasper.reports.compile.temp=/afls_res/booking/managed/cargores/temp"
export JASPER_OPTIONS
JAVA_OPTIONS="-DLogMgr.configFile="/afls_res/booking/managed/cargores/site/aa_site_default.properties" ${ASPECT_VIEWER} ${JASPER_OPTIONS} ${JAVA_OPTIONS}"
export JAVA_OPTIONS

# User to run as
USERNAME="${ANT_OS_USER}"
# Set user-defined variables.
unset JAVA_VM MEM_ARGS

WL_HOME="${ANT_WL_HOME}"
. "${WL_HOME}/common/bin/commEnv.sh"

NODEMGR_HOME="${ANT_NM_HOME}"
pid_file="${NODEMGR_HOME}/pid"

# If NODEMGR_HOME does not exist, create it
if [ ! -d "${NODEMGR_HOME}" ]; then
  echo ""
  echo "NODEMGR_HOME ${NODEMGR_HOME} does not exist, creating it.."
  mkdir -p "${NODEMGR_HOME}"
fi

LISTEN_ADDRESS="${ANT_NM_IP}"
LISTEN_PORT="${ANT_NM_PORT}"

# Check for JDK
if [ ! -d "${JAVA_HOME}/bin" ]; then
  echo "The JDK wasn't found in directory ${JAVA_HOME}."
  echo "Please edit the startNodeManager.sh script so that the JAVA_HOME"
  echo "variable points to the location of your JDK."
  exit 1

else

if [ "${MEM_ARGS}" = "" ]
then
MEM_ARGS=${ANT_MEM_ARGS}
fi

# set -x
CLASSPATH="${WEBLOGIC_CLASSPATH}${CLASSPATHSEP}${CLASSPATH}${CLASSPATHSEP}${BEA_HOME}"
export CLASSPATH
export PATH

case "$1" in
start)
	cd "${NODEMGR_HOME}"
	set -x
	if [ "$LISTEN_PORT" != "" ]
	 then
	   if [ "$LISTEN_ADDRESS" != "" ]
	    then
	     nohup "${JAVA_HOME}/bin/java" -Dnodemanager ${JAVA_VM} ${MEM_ARGS} ${JAVA_OPTIONS} -Djava.security.policy="${WL_HOME}/server/lib/weblogic.policy" -Dweblogic.nodemanager.javaHome="${JAVA_HOME}" -DListenAddress="${LISTEN_ADDRESS}" -DListenPort="${LISTEN_PORT}" weblogic.NodeManager -v > /dev/null 2>&1 &	     
	    else
	     nohup "${JAVA_HOME}/bin/java" -Dnodemanager ${JAVA_VM} ${MEM_ARGS} ${JAVA_OPTIONS} -Djava.security.policy="${WL_HOME}/server/lib/weblogic.policy" -Dweblogic.nodemanager.javaHome="${JAVA_HOME}" -DListenPort="${LISTEN_PORT}" weblogic.NodeManager -v > /dev/null 2>&1 &
	   fi
	 else
	   if [ "$LISTEN_ADDRESS" != "" ]
	    then
	     nohup "${JAVA_HOME}/bin/java" -Dnodemanager ${JAVA_VM} ${MEM_ARGS} ${JAVA_OPTIONS} -Djava.security.policy="${WL_HOME}/server/lib/weblogic.policy" -Dweblogic.nodemanager.javaHome="${JAVA_HOME}" -DListenAddress="${LISTEN_ADDRESS}" weblogic.NodeManager -v > /dev/null 2>&1 &
	    else
	     nohup "${JAVA_HOME}/bin/java" -Dnodemanager ${JAVA_VM} ${MEM_ARGS} ${JAVA_OPTIONS} -Djava.security.policy="${WL_HOME}/server/lib/weblogic.policy" -Dweblogic.nodemanager.javaHome="${JAVA_HOME}" weblogic.NodeManager -v > /dev/null 2>&1 &
	   fi
	fi
	echo $! > $pid_file
	set +x
	sleep 2
	;;

stop)
        if [ -r $pid_file ]; then
        kill `cat $pid_file`
        rm $pid_file
        fi

esac
fi
exit $SMF_EXIT_OK
